﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SMALLERP.DataClass;
using System.Data.SqlClient;
using CrystalDecisions.Shared;
using SMALLERP.ComClass;
using CrystalDecisions.CrystalReports.Engine;
using SMALLERP;

namespace XJLSC.PM
{
    public partial class SCJHDCDY : Form
    {
        public delegate void Cdgzzx(object sender, EventArgs e);
        //定义委托对象
        public Cdgzzx cdgzzx;
        private readonly DataBase db = new DataBase();
        private SqlDataReader sdr1;
        public SCJHDCDY()
        {
            InitializeComponent();
        }

        private void SCJHDCDY_Load(object sender, EventArgs e)
        {

            string sql = null;
            // cryPurReport.ReportSource = commUse.CrystalReports("CryPurReport.rpt", strCondition, "PUInStore");
            sql = "Select * From MOCTY LEFT JOIN MOCTA ON TY001=TA001 AND TY002=TA002 LEFT JOIN INVMB ON TA006=MB001 Where TY003>='" + FMCHAXUN.QSRQ +"' AND TY003<='" + FMCHAXUN.JZRQ + "' AND TA021='" + FMCHAXUN.GZZX + "'";
            DataSet ds = null;
            DataTable dt = null;
            ds = db.GetDataSet1(sql, "MOCTY");
            dt = ds.Tables["MOCTY"];
            SCJHDCBB rpt = new SCJHDCBB();
            string reportPath = Application.StartupPath + "\\PM\\SCJHDCBB.rpt";
            rpt.Load(reportPath);
            TableLogOnInfo objInfo = new TableLogOnInfo();

        //    objInfo.ConnectionInfo.ServerName = PropertyClass.strServer;
        //    objInfo.ConnectionInfo.DatabaseName = PropertyClass.DataBase2;
        //    objInfo.ConnectionInfo.UserID = PropertyClass.strUserID;
        //    objInfo.ConnectionInfo.Password = PropertyClass.strPwd;
        //    rpt.Database.Tables[0].ApplyLogOnInfo(objInfo);

        //    //将数据库信息传递给报表  
        //    rpt.SetDataSource(ds);
        //    rpt.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize;
        //    crystalReportViewer1.ReportSource = rpt;

        //    string subreportName;
        //    SubreportObject subreportObject;
        //    ReportDocument subreport = new ReportDocument();
        //    subreportObject = rpt.ReportDefinition.ReportObjects["Subreport2"] as SubreportObject;

        //    // 按名称获取 ReportObject 并将其转换为
        //    // SubreportObject。

        //    if (subreportObject != null)
        //    {
        //        // 获取子报表名称。
        //        subreportName = subreportObject.SubreportName;
        //        // 打开子报表作为 ReportDocument。
        //        subreport = subreportObject.OpenSubreport(subreportName);

        //        //设置logOnInfo参数
        //        objInfo.ConnectionInfo.ServerName = PropertyClass.strServer;
        //        objInfo.ConnectionInfo.DatabaseName = PropertyClass.DataBase2;
        //        objInfo.ConnectionInfo.UserID = PropertyClass.strUserID;
        //        objInfo.ConnectionInfo.Password = PropertyClass.strPwd;
        //        subreport.Database.Tables[0].ApplyLogOnInfo(objInfo);
        //    }
        //    subreportObject = rpt.ReportDefinition.ReportObjects["Subreport1"] as SubreportObject;

        //    // 按名称获取 ReportObject 并将其转换为
        //    // SubreportObject。

        //    if (subreportObject != null)
        //    {
        //        // 获取子报表名称。
        //        subreportName = subreportObject.SubreportName;
        //        // 打开子报表作为 ReportDocument。
        //        subreport = subreportObject.OpenSubreport(subreportName);

        //        //设置logOnInfo参数
        //        objInfo.ConnectionInfo.ServerName = PropertyClass.strServer;
        //        objInfo.ConnectionInfo.DatabaseName = PropertyClass.DataBase2;
        //        objInfo.ConnectionInfo.UserID = PropertyClass.strUserID;
        //        objInfo.ConnectionInfo.Password = PropertyClass.strPwd;
        //        subreport.Database.Tables[0].ApplyLogOnInfo(objInfo);
        //    }
        //    subreportObject = rpt.ReportDefinition.ReportObjects["Subreport3"] as SubreportObject;

        //    // 按名称获取 ReportObject 并将其转换为
        //    // SubreportObject。

        //    if (subreportObject != null)
        //    {
        //        // 获取子报表名称。
        //        subreportName = subreportObject.SubreportName;
        //        // 打开子报表作为 ReportDocument。
        //        subreport = subreportObject.OpenSubreport(subreportName);

        //        //设置logOnInfo参数
        //        objInfo.ConnectionInfo.ServerName = PropertyClass.strServer;
        //        objInfo.ConnectionInfo.DatabaseName = PropertyClass.DataBase2;
        //        objInfo.ConnectionInfo.UserID = PropertyClass.strUserID;
        //        objInfo.ConnectionInfo.Password = PropertyClass.strPwd;
        //        subreport.Database.Tables[0].ApplyLogOnInfo(objInfo);
        //    }
        //    subreportObject = rpt.ReportDefinition.ReportObjects["Subreport4"] as SubreportObject;

        //    // 按名称获取 ReportObject 并将其转换为
        //    // SubreportObject。

        //    if (subreportObject != null)
        //    {
        //        // 获取子报表名称。
        //        subreportName = subreportObject.SubreportName;
        //        // 打开子报表作为 ReportDocument。
        //        subreport = subreportObject.OpenSubreport(subreportName);

        //        //设置logOnInfo参数
        //        objInfo.ConnectionInfo.ServerName = PropertyClass.strServer;
        //        objInfo.ConnectionInfo.DatabaseName = PropertyClass.DataBase2;
        //        objInfo.ConnectionInfo.UserID = PropertyClass.strUserID;
        //        objInfo.ConnectionInfo.Password = PropertyClass.strPwd;
        //        subreport.Database.Tables[0].ApplyLogOnInfo(objInfo);
           } 

        }
    }
        
    

